package com.example.myone.Util;

import android.os.Build;

import androidx.annotation.RequiresApi;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@RequiresApi(api = Build.VERSION_CODES.O)
public class DateTimeUtil {
    private static final LocalDate now = LocalDate.now();
    public static String getNowStr() {
        return now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }
    public static String getNowYearMonthStr() {
        return now.format(DateTimeFormatter.ofPattern("yyyy-MM"));
    }

    public static String getNowDay() {
        return now.format(DateTimeFormatter.ofPattern("dd"));
    }

    public static String getNowMonthCN() {
        return now.format(DateTimeFormatter.ofPattern("MMM"));
    }

    public static String getNowMonth() {
        return now.format(DateTimeFormatter.ofPattern("MM"));
    }

    public static String getNowYear() {
        return now.format(DateTimeFormatter.ofPattern("yyyy"));
    }

    public static String getDay(LocalDate localDate) {
        return localDate.format(DateTimeFormatter.ofPattern("dd"));
    }

    public static String getMonthCN(LocalDate localDate) {
        return localDate.format(DateTimeFormatter.ofPattern("MMM"));
    }

    public static String getMonth(LocalDate localDate) {
        return localDate.format(DateTimeFormatter.ofPattern("MM"));
    }

    public static String getYear(LocalDate localDate) {
        return localDate.format(DateTimeFormatter.ofPattern("yyyy"));
    }

    public static LocalDate getLocalDate(String dateString) {
        return LocalDate.parse(dateString, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }

    public static boolean isToday(String dateString) {
        return LocalDate.parse(dateString, DateTimeFormatter.ofPattern("yyyy-MM-dd")).equals(now);
    }
}
